<html>
<head><meta charset="utf-8"><title>How does Rust represent the symbol table in the compiler? · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html">How does Rust represent the symbol table in the compiler?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="218853762"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218853762" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joe Seriah <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218853762">(Dec 04 2020 at 16:13)</a>:</h4>
<p>Hi,</p>
<p>New here and had a general question about Rust. I noticed that you can have an arbitrary amount of modules within modules and was wondering how rust handles this scoping?</p>
<ul>
<li>One way I can think of, to clarify my question, is to use a hashmap. However, this does not seem performant when you want to type check and you need to call the hashmap 10 times.</li>
</ul>
<p>If I may clarify again, I was wondering about how this was done before the query system was implemented.</p>
<p>Hope it's clear</p>



<a name="218854072"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218854072" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218854072">(Dec 04 2020 at 16:14)</a>:</h4>
<p>Are you looking for <a href="https://rustc-dev-guide.rust-lang.org/name-resolution.html?highlight=resolve#name-resolution">https://rustc-dev-guide.rust-lang.org/name-resolution.html?highlight=resolve#name-resolution</a> ?</p>



<a name="218854587"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218854587" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joe Seriah <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218854587">(Dec 04 2020 at 16:17)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232545">Joshua Nelson</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F/near/218854072">said</a>:</p>
<blockquote>
<p>Are you looking for <a href="https://rustc-dev-guide.rust-lang.org/name-resolution.html?highlight=resolve#name-resolution">https://rustc-dev-guide.rust-lang.org/name-resolution.html?highlight=resolve#name-resolution</a> ?</p>
</blockquote>
<p>I think I was more interested in how something like the below code snippet was represtented in the compiler:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">mod</span> <span class="nn">foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">   </span><span class="k">mod</span> <span class="nn">bar</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">       </span><span class="k">mod</span> <span class="nn">another_one</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">call_me_maybe</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="kt">u32</span> <span class="p">{</span><span class="mi">0</span><span class="p">}</span><span class="w"></span>
<span class="w">       </span><span class="p">}</span><span class="w"></span>
<span class="w">   </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="218854786"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218854786" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joe Seriah <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218854786">(Dec 04 2020 at 16:19)</a>:</h4>
<p>Does each module have it's own symbol table as a hashmap, where calling the <code>call_me_maybe()</code> function require 3 get() calls to access the <code>call_me_maybe</code> function?</p>



<a name="218854789"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218854789" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218854789">(Dec 04 2020 at 16:19)</a>:</h4>
<p>type checking just uses a visitor to traverse the whole crate iirc</p>



<a name="218855001"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218855001" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218855001">(Dec 04 2020 at 16:21)</a>:</h4>
<p>rustc pretty much has a flat storage for things like this with references to the parents of items</p>



<a name="218855017"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218855017" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218855017">(Dec 04 2020 at 16:21)</a>:</h4>
<p><span class="user-mention silent" data-user-id="364259">Joe Seriah</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F/near/218854786">said</a>:</p>
<blockquote>
<p>Does each module have it's own symbol table as a hashmap, where calling the <code>call_me_maybe()</code> function require 3 get() calls to access the <code>call_me_maybe</code> function?</p>
</blockquote>
<p>this is the way modules are represented in the HIR: <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/struct.Mod.html">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/struct.Mod.html</a>. But most of the time you already know what function you're dealing with and look it up with a DefId directly</p>



<a name="218855061"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218855061" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218855061">(Dec 04 2020 at 16:21)</a>:</h4>
<p>(and yes, rustc is very much a giant hashmap stress test)</p>



<a name="218855157"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218855157" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joe Seriah <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218855157">(Dec 04 2020 at 16:22)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F/near/218855001">said</a>:</p>
<blockquote>
<p>rustc pretty much has a flat storage for things like this with references to the parents of items</p>
</blockquote>
<p>Do you mean that the items are stored in an array and there is a hashmap which references them?</p>



<a name="218855194"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218855194" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218855194">(Dec 04 2020 at 16:22)</a>:</h4>
<p>rustc's memory management is complicated</p>



<a name="218855208"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218855208" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218855208">(Dec 04 2020 at 16:22)</a>:</h4>
<p>it depends on which of the IRs you're asking about</p>



<a name="218855212"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218855212" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218855212">(Dec 04 2020 at 16:22)</a>:</h4>
<p>Modules are stored in a <code>BTreeMap&lt;HirId, Module&gt;</code>in hir iirc</p>



<a name="218855221"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218855221" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218855221">(Dec 04 2020 at 16:22)</a>:</h4>
<p>there's AST, HIR, and MIR</p>



<a name="218855244"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218855244" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218855244">(Dec 04 2020 at 16:22)</a>:</h4>
<p>but yeah, what <span class="user-mention silent" data-user-id="232545">Joshua Nelson</span>  said</p>



<a name="218855325"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218855325" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joe Seriah <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218855325">(Dec 04 2020 at 16:23)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232545">Joshua Nelson</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F/near/218855017">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="364259">Joe Seriah</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F/near/218854786">said</a>:</p>
<blockquote>
<p>Does each module have it's own symbol table as a hashmap, where calling the <code>call_me_maybe()</code> function require 3 get() calls to access the <code>call_me_maybe</code> function?</p>
</blockquote>
<p>this is the way modules are represented in the HIR: <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/struct.Mod.html">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/struct.Mod.html</a>. But most of the time you already know what function you're dealing with and look it up with a DefId directly</p>
</blockquote>
<p>How would you know what function you want to call if you do type checking after parsing?</p>



<a name="218855406"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218855406" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joe Seriah <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218855406">(Dec 04 2020 at 16:24)</a>:</h4>
<p>Since after parsing, I do not think you have linked any of the symbols together?</p>



<a name="218855408"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218855408" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218855408">(Dec 04 2020 at 16:24)</a>:</h4>
<p>you want to know how name resolution works?</p>



<a name="218855502"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218855502" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218855502">(Dec 04 2020 at 16:24)</a>:</h4>
<p>so how <code>test</code> knows which <code>foo</code> it should use?</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">foo</span><span class="p">()</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="k">mod</span> <span class="nn">i</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">foo</span><span class="p">()</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="w">    </span><span class="k">mod</span> <span class="nn">j</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="k">use</span><span class="w"> </span><span class="k">super</span>::<span class="o">*</span><span class="p">;</span><span class="w"></span>
<span class="w">        </span><span class="k">fn</span> <span class="nf">test</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">foo</span><span class="p">()</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="218855689"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218855689" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joe Seriah <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218855689">(Dec 04 2020 at 16:26)</a>:</h4>
<p>I believe I would like to find out how symbol linking and resolution works if I want to type check a function call from a different module. Or maybe that's what you mean?</p>



<a name="218855785"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218855785" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218855785">(Dec 04 2020 at 16:27)</a>:</h4>
<p>"type check a function call from a different module" doesn't really makes sense, we typecheck each function by itself</p>



<a name="218855795"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218855795" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218855795">(Dec 04 2020 at 16:27)</a>:</h4>
<p>I think you mean name resolution</p>



<a name="218855798"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218855798" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joe Seriah <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218855798">(Dec 04 2020 at 16:27)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F/near/218855502">said</a>:</p>
<blockquote>
<p>so how <code>test</code> knows which <code>foo</code> it should use?</p>
<p><div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">foo</span><span class="p">()</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="k">mod</span> <span class="nn">i</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">foo</span><span class="p">()</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="w">    </span><span class="k">mod</span> <span class="nn">j</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="k">use</span><span class="w"> </span><span class="k">super</span>::<span class="o">*</span><span class="p">;</span><span class="w"></span>
<span class="w">        </span><span class="k">fn</span> <span class="nf">test</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">foo</span><span class="p">()</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div><br>
</p>
</blockquote>
<p>In this example, I believe it would call the foo that was one up from it since Rust uses lexical scoping?</p>



<a name="218855915"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218855915" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joe Seriah <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218855915">(Dec 04 2020 at 16:28)</a>:</h4>
<p><span class="user-mention silent" data-user-id="211727">Jonas Schievink</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F/near/218855795">said</a>:</p>
<blockquote>
<p>I think you mean name resolution</p>
</blockquote>
<p>Sorry my terminology is bad. I believe I mean name resolution</p>



<a name="218855967"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218855967" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218855967">(Dec 04 2020 at 16:28)</a>:</h4>
<p>it probably helps to read <a href="https://rustc-dev-guide.rust-lang.org/name-resolution.html">https://rustc-dev-guide.rust-lang.org/name-resolution.html</a> then</p>



<a name="218856485"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218856485" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joe Seriah <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218856485">(Dec 04 2020 at 16:32)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F/near/218855967">said</a>:</p>
<blockquote>
<p>it probably helps to read <a href="https://rustc-dev-guide.rust-lang.org/name-resolution.html">https://rustc-dev-guide.rust-lang.org/name-resolution.html</a> then</p>
</blockquote>
<p>I read this, it seems to be missing the information I was looking for, unless I missed it.</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">mod</span> <span class="nn">foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">   </span><span class="k">mod</span> <span class="nn">bar</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">      </span><span class="k">fn</span> <span class="nf">call</span><span class="p">()</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="w">  </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="n">foo</span>::<span class="n">bar</span>::<span class="n">call</span><span class="p">()</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>When the resolver encounters the <code>call</code> expression, do you know how it finds the call symbol?</p>



<a name="218856829"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218856829" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joe Seriah <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218856829">(Dec 04 2020 at 16:34)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F/near/218855212">said</a>:</p>
<blockquote>
<p>Modules are stored in a <code>BTreeMap&lt;HirId, Module&gt;</code>in hir iirc</p>
</blockquote>
<p>From this, I'm guessing that it does </p>
<p>let foo = BTreeMap.get(foo);<br>
let bar = foo.get(bar);<br>
let call = bar.func_get(call);</p>
<p>?</p>



<a name="218857047"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218857047" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joe Seriah <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218857047">(Dec 04 2020 at 16:36)</a>:</h4>
<p>But this does not seem quite right, because I interpreted previous messages as saying that there was a flat structure. So I'm a bit confused as to how you keep the scoping information. ie bar is inside of foo</p>
<p>Sorry if it is not making much sense</p>



<a name="218857083"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218857083" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218857083">(Dec 04 2020 at 16:36)</a>:</h4>
<p>well, <em>only</em> name resolution cares about scoping really</p>



<a name="218857091"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218857091" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218857091">(Dec 04 2020 at 16:36)</a>:</h4>
<p>The "flat structure" is only present after name resolution, in the form of <code>DefId</code>s</p>



<a name="218857121"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218857121" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joe Seriah <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218857121">(Dec 04 2020 at 16:37)</a>:</h4>
<p>What about type checking?</p>



<a name="218857144"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218857144" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218857144">(Dec 04 2020 at 16:37)</a>:</h4>
<p>type checking comes after name resoultion, so it uses DefIds</p>



<a name="218857290"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218857290" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joe Seriah <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218857290">(Dec 04 2020 at 16:38)</a>:</h4>
<p>Or does name resolution also modify the AST so that instead of seeing <code>foo::bar::call</code> it sees something like <code>DefId</code>?</p>



<a name="218857409"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218857409" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joe Seriah <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218857409">(Dec 04 2020 at 16:39)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232545">Joshua Nelson</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F/near/218857144">said</a>:</p>
<blockquote>
<p>type checking comes after name resoultion, so it uses DefIds</p>
</blockquote>
<p>Oh it's starting to make a bit of sense, I naively thought that name resolution did not modify the AST</p>



<a name="218857423"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218857423" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218857423">(Dec 04 2020 at 16:39)</a>:</h4>
<p>it does not</p>



<a name="218857432"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218857432" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218857432">(Dec 04 2020 at 16:39)</a>:</h4>
<p>type checking does not work on an AST</p>



<a name="218857463"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218857463" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218857463">(Dec 04 2020 at 16:39)</a>:</h4>
<p>it walks the crate with intravisit I think <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/intravisit/trait.Visitor.html">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/intravisit/trait.Visitor.html</a></p>



<a name="218857492"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218857492" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218857492">(Dec 04 2020 at 16:39)</a>:</h4>
<p>which works on the HIR</p>



<a name="218857618"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218857618" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joe Seriah <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218857618">(Dec 04 2020 at 16:40)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232545">Joshua Nelson</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F/near/218857432">said</a>:</p>
<blockquote>
<p>type checking does not work on an AST</p>
</blockquote>
<p>Oh sorry, so name resolution works on the AST and type checking works on the HIR?</p>



<a name="218857651"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218857651" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218857651">(Dec 04 2020 at 16:40)</a>:</h4>
<p>I think so</p>



<a name="218857673"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218857673" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218857673">(Dec 04 2020 at 16:40)</a>:</h4>
<p>yes</p>



<a name="218857792"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218857792" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joe Seriah <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218857792">(Dec 04 2020 at 16:41)</a>:</h4>
<p>Do you know if the AST is transformed into the HIR during name resolution or is it done as a separate pass?</p>



<a name="218857821"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218857821" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218857821">(Dec 04 2020 at 16:41)</a>:</h4>
<p>separately</p>



<a name="218857897"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218857897" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218857897">(Dec 04 2020 at 16:42)</a>:</h4>
<p>this is done by <code>rustc_ast_lowering</code>: <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast_lowering/index.html">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast_lowering/index.html</a></p>



<a name="218858168"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218858168" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joe Seriah <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218858168">(Dec 04 2020 at 16:44)</a>:</h4>
<p><span class="user-mention silent" data-user-id="211727">Jonas Schievink</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F/near/218857821">said</a>:</p>
<blockquote>
<p>separately</p>
</blockquote>
<p>Oh okay thanks. To clarify the AST is walked twice before it is thrown away then? Once during name resolution and another during ast_lowering?</p>
<p>I'm guessing the reason it was done as a separate pass is to make the code clearer?</p>



<a name="218858258"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218858258" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218858258">(Dec 04 2020 at 16:44)</a>:</h4>
<p>at least twice, yeah</p>



<a name="218858294"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218858294" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218858294">(Dec 04 2020 at 16:45)</a>:</h4>
<p>and once for AST validation</p>



<a name="218858323"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218858323" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218858323">(Dec 04 2020 at 16:45)</a>:</h4>
<p>and probably again for some other things I don't know about</p>



<a name="218858677"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218858677" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joe Seriah <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218858677">(Dec 04 2020 at 16:47)</a>:</h4>
<p><span class="user-mention silent" data-user-id="211727">Jonas Schievink</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F/near/218858258">said</a>:</p>
<blockquote>
<p>at least twice, yeah</p>
</blockquote>
<p>Maybe I also ask how the <code>use</code> import is processed?</p>



<a name="218858932"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218858932" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218858932">(Dec 04 2020 at 16:49)</a>:</h4>
<p>name resolution in Rust is a fixed-point algorithm, and is interleaved with macro expansion</p>



<a name="218858933"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218858933" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joe Seriah <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218858933">(Dec 04 2020 at 16:49)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">use</span><span class="w"> </span><span class="n">foo</span>::<span class="n">hello</span><span class="p">;</span><span class="w"></span>
<span class="n">hello</span>::<span class="n">bar</span><span class="p">()</span><span class="w"></span>
</code></pre></div>
<p>Does this become:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="n">foo</span>::<span class="n">hello</span>::<span class="n">bar</span><span class="p">()</span><span class="w"></span>
</code></pre></div>
<p>?</p>



<a name="218858975"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218858975" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218858975">(Dec 04 2020 at 16:49)</a>:</h4>
<p>that means that <code>use</code> items might initially not be resolved, because they refer to items produced by a macro</p>



<a name="218859002"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218859002" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218859002">(Dec 04 2020 at 16:50)</a>:</h4>
<p>oh, no, it doesn't do any AST rewriting</p>



<a name="218859125"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218859125" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218859125">(Dec 04 2020 at 16:50)</a>:</h4>
<p>it keeps a list of unresolved imports and runs a fixed-point algorithm on them until they're all resolved</p>



<a name="218859166"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218859166" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218859166">(Dec 04 2020 at 16:50)</a>:</h4>
<p>then the resolution is stored in the name resolution data</p>



<a name="218859194"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218859194" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218859194">(Dec 04 2020 at 16:51)</a>:</h4>
<p>resolution being <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/def/enum.Res.html"><code>Res</code></a>, I believe</p>



<a name="218859498"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218859498" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joe Seriah <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218859498">(Dec 04 2020 at 16:53)</a>:</h4>
<p><span class="user-mention silent" data-user-id="211727">Jonas Schievink</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F/near/218859125">said</a>:</p>
<blockquote>
<p>it keeps a list of unresolved imports and runs a fixed-point algorithm on them until they're all resolved</p>
</blockquote>
<p>Oh, so if I have:</p>
<div class="codehilite"><pre><span></span><code>use foo::bar
</code></pre></div>
<p>Then this is resolved to the <code>bar</code> module inside of <code>foo</code> and then it is added to the resolution data, to be used for name resolving the rest of the file?</p>



<a name="218859973"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218859973" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218859973">(Dec 04 2020 at 16:56)</a>:</h4>
<p>I think so, yeah</p>



<a name="218860385"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218860385" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joe Seriah <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218860385">(Dec 04 2020 at 17:00)</a>:</h4>
<p><span class="user-mention silent" data-user-id="211727">Jonas Schievink</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F/near/218859973">said</a>:</p>
<blockquote>
<p>I think so, yeah</p>
</blockquote>
<p>Thank you, and I'm guessing that the contents of <code>Res</code> is a linker to the symbol in some other crate?</p>
<div class="codehilite"><pre><span></span><code>use foo::bar
bar::hello()
</code></pre></div>
<p>In the above code, I'm guessing that it does not return the AST for bar module because then it would need to do it per use statement</p>



<a name="218860528"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218860528" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218860528">(Dec 04 2020 at 17:00)</a>:</h4>
<p>Res contains a DefId</p>



<a name="218860539"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218860539" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joe Seriah <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218860539">(Dec 04 2020 at 17:00)</a>:</h4>
<p>So maybe:</p>
<p>ResolutionData.insert("bar", ModID) if it is a module and DefID if it is a function for example</p>



<a name="218860552"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218860552" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218860552">(Dec 04 2020 at 17:01)</a>:</h4>
<p><a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/def/enum.Res.html">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/def/enum.Res.html</a></p>



<a name="218860637"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218860637" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218860637">(Dec 04 2020 at 17:01)</a>:</h4>
<p><span class="user-mention silent" data-user-id="211727">Jonas Schievink</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F/near/218859002">said</a>:</p>
<blockquote>
<p>oh, no, it doesn't do any AST rewriting</p>
</blockquote>
<p>(this isn't really true, I think macro expansion rewrites the AST in-place)</p>



<a name="218860662"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218860662" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joe Seriah <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218860662">(Dec 04 2020 at 17:01)</a>:</h4>
<p>Oh sorry DefId is not only for functions</p>



<a name="218860688"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218860688" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218860688">(Dec 04 2020 at 17:02)</a>:</h4>
<p>yeah it's for any definition that's cross-crate</p>



<a name="218860743"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218860743" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218860743">(Dec 04 2020 at 17:02)</a>:</h4>
<p><a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/def/enum.DefKind.html">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/def/enum.DefKind.html</a></p>



<a name="218860874"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218860874" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joe Seriah <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218860874">(Dec 04 2020 at 17:03)</a>:</h4>
<p><span class="user-mention silent" data-user-id="211727">Jonas Schievink</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F/near/218860637">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="211727">Jonas Schievink</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F/near/218859002">said</a>:</p>
<blockquote>
<p>oh, no, it doesn't do any AST rewriting</p>
</blockquote>
<p>(this isn't really true, I think macro expansion rewrites the AST in-place)</p>
</blockquote>
<p>Oh that makes sense as to why compile times are longer with macros, thanks for correcting me</p>



<a name="218860920"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218860920" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joe Seriah <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218860920">(Dec 04 2020 at 17:03)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232545">Joshua Nelson</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F/near/218860743">said</a>:</p>
<blockquote>
<p><a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/def/enum.DefKind.html">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/def/enum.DefKind.html</a></p>
</blockquote>
<p>Is DefID available in HIR and AST?</p>



<a name="218861054"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218861054" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218861054">(Dec 04 2020 at 17:04)</a>:</h4>
<p><code>DefId</code> is only available for HIR. AST uses <code>NodeId</code> I think.</p>
<p>Edit: maybe it is possible to use a <code>DefId</code> for defs in a different crate?</p>



<a name="218861105"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218861105" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218861105">(Dec 04 2020 at 17:04)</a>:</h4>
<p><code>DefKind</code> is one of the types that forms the HIR.</p>



<a name="218861471"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218861471" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joe Seriah <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218861471">(Dec 04 2020 at 17:07)</a>:</h4>
<p><span class="user-mention silent" data-user-id="133247">bjorn3</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F/near/218861054">said</a>:</p>
<blockquote>
<p><code>DefId</code> is only available for HIR. AST uses <code>NodeId</code> I think.</p>
</blockquote>
<p>Oh in name resolution, both DefId and NodeId is used?</p>



<a name="218861556"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218861556" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218861556">(Dec 04 2020 at 17:08)</a>:</h4>
<p>nameres doesn't use HIR</p>



<a name="218861676"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218861676" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218861676">(Dec 04 2020 at 17:08)</a>:</h4>
<p>Name resolution imports <code>DefId</code> and <code>DefKind</code>: <a href="https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_resolve/lib.rs.html#39">https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_resolve/lib.rs.html#39</a></p>



<a name="218861711"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218861711" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joe Seriah <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218861711">(Dec 04 2020 at 17:09)</a>:</h4>
<p><span class="user-mention silent" data-user-id="211727">Jonas Schievink</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F/near/218861556">said</a>:</p>
<blockquote>
<p>nameres doesn't use HIR</p>
</blockquote>
<p>Oh sorry, I thought the <code>Res</code> structure which has <code>DefID</code> was used in nameres</p>



<a name="218861891"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218861891" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218861891">(Dec 04 2020 at 17:10)</a>:</h4>
<p>ah, seems like DefIds are assigned earlier then</p>



<a name="218861909"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218861909" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218861909">(Dec 04 2020 at 17:10)</a>:</h4>
<p>or at least partially</p>



<a name="218862586"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218862586" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joe Seriah <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218862586">(Dec 04 2020 at 17:15)</a>:</h4>
<p><span class="user-mention silent" data-user-id="211727">Jonas Schievink</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F/near/218861891">said</a>:</p>
<blockquote>
<p>ah, seems like DefIds are assigned earlier then</p>
</blockquote>
<p>Ah okay, thanks for checking.</p>
<div class="codehilite"><pre><span></span><code>use foo::bar
bar::hello()
</code></pre></div>
<p>To clarify my understanding using the example above.</p>
<p>In name resolution, we resolve the use statement to be <code>Res(DefID)</code></p>
<p>We then add it to the current resolvers resolution data, so <code>ResolutionData.insert("bar", Res)</code></p>
<p>When I see <code>bar::hello</code> the compiler will do <code>bar_module = ResolutionData.get(ctx, "bar")</code></p>
<p>then it will do <code>bar_module.get_func(hello)</code></p>
<p>Is this correct?</p>



<a name="218862696"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218862696" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218862696">(Dec 04 2020 at 17:16)</a>:</h4>
<p>not sure how it works in detail, I suggest checking the code directly</p>



<a name="218862774"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218862774" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joe Seriah <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218862774">(Dec 04 2020 at 17:17)</a>:</h4>
<p>Okay thanks for the help. Do you mind slightly elaborating on what you mean by a fixed-point algorithm?</p>



<a name="218862829"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218862829" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joe Seriah <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218862829">(Dec 04 2020 at 17:17)</a>:</h4>
<p><span class="user-mention silent" data-user-id="211727">Jonas Schievink</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F/near/218858932">said</a>:</p>
<blockquote>
<p>name resolution in Rust is a fixed-point algorithm, and is interleaved with macro expansion</p>
</blockquote>
<p>mentioned here for clarification</p>



<a name="218862872"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218862872" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218862872">(Dec 04 2020 at 17:17)</a>:</h4>
<p><a href="https://rustc-dev-guide.rust-lang.org/macro-expansion.html#expansion-and-ast-integration">https://rustc-dev-guide.rust-lang.org/macro-expansion.html#expansion-and-ast-integration</a></p>



<a name="218862903"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218862903" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218862903">(Dec 04 2020 at 17:18)</a>:</h4>
<p>most of this info is in the dev-guide btw</p>



<a name="218862990"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218862990" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218862990">(Dec 04 2020 at 17:18)</a>:</h4>
<p>This is the crux of name resolution: <a href="https://github.com/rust-analyzer/rust-analyzer/blob/b988c6f84e06bdc5562c70f28586b9eeaae3a39c/crates/hir_def/src/nameres/collector.rs#L234-L248">https://github.com/rust-analyzer/rust-analyzer/blob/b988c6f84e06bdc5562c70f28586b9eeaae3a39c/crates/hir_def/src/nameres/collector.rs#L234-L248</a></p>



<a name="218863049"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218863049" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218863049">(Dec 04 2020 at 17:19)</a>:</h4>
<p>Ah that dev guide page explains it well</p>



<a name="218863098"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218863098" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joe Seriah <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218863098">(Dec 04 2020 at 17:19)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232545">Joshua Nelson</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F/near/218862903">said</a>:</p>
<blockquote>
<p>most of this info is in the dev-guide btw</p>
</blockquote>
<p>Thanks for the link, yeah sorry I've been reading it also, just a bit slow haha</p>



<a name="218863244"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218863244" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joe Seriah <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218863244">(Dec 04 2020 at 17:20)</a>:</h4>
<p><span class="user-mention silent" data-user-id="211727">Jonas Schievink</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F/near/218862990">said</a>:</p>
<blockquote>
<p>This is the crux of name resolution: <a href="https://github.com/rust-analyzer/rust-analyzer/blob/b988c6f84e06bdc5562c70f28586b9eeaae3a39c/crates/hir_def/src/nameres/collector.rs#L234-L248">https://github.com/rust-analyzer/rust-analyzer/blob/b988c6f84e06bdc5562c70f28586b9eeaae3a39c/crates/hir_def/src/nameres/collector.rs#L234-L248</a></p>
</blockquote>
<p>Oh I've never heard of the term fixed-point algorithm, I was wondering what it meant in the context of name resolution?</p>



<a name="218863647"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20does%20Rust%20represent%20the%20symbol%20table%20in%20the%20compiler%3F/near/218863647" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joe Seriah <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20does.20Rust.20represent.20the.20symbol.20table.20in.20the.20compiler.3F.html#218863647">(Dec 04 2020 at 17:23)</a>:</h4>
<p>Oh found the definition: <a href="https://en.wikipedia.org/wiki/Fixed-point_iteration">https://en.wikipedia.org/wiki/Fixed-point_iteration</a></p>
<p>Thanks again for the help!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>